index.js ➔ ???   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 20
rs 9.4285
1
/**
2
 * Entry point
3
 */
4
import { resolve } from 'path';
5
import logger from 'winston';
6
import Webpack from 'webpack';
7
import WebpackDevServer from 'webpack-dev-server';
8
import H2O2 from 'h2o2';
9
import server from './server';
10
import webpackConfig from '../webpack.config';
11
import config from './config/server.config';
12
13
if (process.env.NODE_ENV === 'development') {
14
  // IN DEVELOPMENT
15
16
  new WebpackDevServer(Webpack(webpackConfig), {
17
    hot: true,
18
    contentBase: resolve(__dirname, `${config.build.clientOutputDirectoryName}`),
19
    publicPath: `http://${config.defaults.host}:${config.build.webpackServerPort}${config.url.publicPrefix}/`,
20
    headers: { 'Access-Control-Allow-Origin': '*' },
21
  }).listen(config.build.webpackServerPort, config.defaults.host, (err) => {
22
    if (err) {
23
      logger.error(err);
24
      return;
25
    }
26
    logger.log(`Webpack dev server listening at ${config.defaults.host}:${config.build.webpackServerPort}`);
27
28
    server.addPlugin({ register: H2O2 });
29
30
    server.start([
31
      {
32
        method: 'GET',
33
        path: `${config.url.publicPrefix}/{path*}`,
34
        handler: {
35
          proxy: { host: config.defaults.host, port: config.build.webpackServerPort, passThrough: true },
36
        },
37
        config: { auth: false },
38
      },
39
    ]);
40
  });
41
} else {
42
  // IN PRODUCTION
43
  server.start([
44
    {
45
      method: 'GET',
46
      path: `${config.url.publicPrefix}/{path*}`,
47
      handler: {
48
        directory: { path: config.directory.public, listing: true },
49
      },
50
      config: { auth: false },
51
    }
52
  ]);
53
}
54